<%-- 
    Document   : StartTest
    Created on : Mar 23, 2012, 1:11:36 AM
    Author     : Tri ben tre
--%>

<%@page import="java.util.Hashtable"%>
<%@page import="COMMON.NganHangCauHoi"%>
<%@page import="COMMON.CauHoi"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    long timer = (Long) request.getAttribute("timer");
    String checked = "";
    String[] sar = null;
    Hashtable ht = new Hashtable();
    if (session.getAttribute("checked") != null) {
        checked = (String) session.getAttribute("checked");
        sar = checked.split(",");

        for (int i = 0; i < sar[0].length(); i++) {
            ht.put(Character.toString(sar[0].charAt(i)), Character.toString(sar[1].charAt(i)));
        }
    }
    ArrayList<CauHoi> dsch = (ArrayList<CauHoi>) request.getAttribute("dsch");

%>

<div id="content">
    <h3 class="hr_divider">Beginning test - exam code: <%= request.getAttribute("examCode")%></h3>
    <div style="margin: 3px;"><button class="NFButton" id="defaultCountdown" onclick="return false;"></button></div>

    <script type="text/javascript">
        $(function () {
            //window.history.forward(-1); // Bỏ dòng này khi back nó sẽ thi lại đề mới hoàn toàn.
            $('#defaultCountdown').countdown({until: <%= timer %>, compact: true, 
                description: '', onExpiry: liftOff});
            
            function liftOff() {
                alert("The test was out of time. Click OK and view result of you!");
                $('#frm1').submit();
            } 
        });
    </script>
    <p><b>Four words or phrases, labelled 1, 2, 3, and 4, are given below the conversation. Choose the word or phrase that will correctly complete the conversation. Click on the answer you think is correct.</b></p>
    <%
        int allCheck = (Integer) request.getAttribute("allCheck");
        if (allCheck == 1) {
    %>
    <div style="text-align: right;"><button onclick="return getRadioButtonNotChecked(<%= dsch.size()%>);">Finish and view result</button></div>
    <% } else {
    %>
    <div style="text-align: right;"><button>Finish and view result</button></div>            
    <% }%>
    <%
        int examCode = Integer.parseInt(request.getAttribute("examCode").toString());

        String str = "";// Lưu lại thứ tự các câu hỏi đã random để show kết quả
        for (int i = 1; i <= dsch.size(); i++) {
            CauHoi ch = dsch.get(i - 1);
            str = str + ch.getIdcauhoi();
            if (i != dsch.size()) {
                str = str + ",";
            }
    %>

    <div class="post_box">
        <div class="post_meta"><%= i%>.<%= ch.getQuestion()%> (<% if (ch.getLevel() == 1) {
                out.println("Easy");
            } else if (ch.getLevel() == 2) {
                out.println("Medium");
            } else if (ch.getLevel() == 3) {
                out.println("Hard");
            }%>)</div>
        <div><input type="radio" name="<%= i%>" id="answerA<%= i%>" value="1" <% if (ht.size() > 0) {
                if (ht.get(Integer.toString(i)) != null && ht.get(Integer.toString(i)).equals("1")) {
                    out.println("checked='checked'");
                }
            }%>/><label for="answerA<%= i%>" class="opt"><%= ch.getAnswer_1()%></label></div>
        <div><input type="radio" name="<%= i%>" id="answerB<%= i%>" value="2" <% if (ht.size() > 0) {
                if (ht.get(Integer.toString(i)) != null && ht.get(Integer.toString(i)).equals("2")) {
                    out.println("checked='checked'");
                }
            }%>/><label for="answerB<%= i%>" class="opt"><%= ch.getAnswer_2()%></div>
        <div><input type="radio" name="<%= i%>" id="answerC<%= i%>" value="3" <% if (ht.size() > 0) {
                if (ht.get(Integer.toString(i)) != null && ht.get(Integer.toString(i)).equals("3")) {
                    out.println("checked='checked'");
                }
            }%>/><label for="answerC<%= i%>" class="opt"><%= ch.getAnswer_3()%></label></div>
        <div><input type="radio" name="<%= i%>" id="answerD<%= i%>" value="4" <% if (ht.size() > 0) {
                if (ht.get(Integer.toString(i)) != null && ht.get(Integer.toString(i)).equals("4")) {
                    out.println("checked='checked'");
                }
            }%>/><label for="answerD<%= i%>" class="opt"><%= ch.getAnswer_4()%> from</label></div>
        <div class="cleaner"></div>
    </div>
    <%
        }
        response.setHeader("Cache-control", "no-cache, no-store");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Expires", "-1");
    %>
    <%
        if (allCheck == 1) {
    %>
    <div style="text-align: right;"><button onclick="return getRadioButtonNotChecked(<%= dsch.size()%>);">Finish and view result</button></div>
    <% } else {
    %>
    <div style="text-align: right;"><button>Finish and view result</button></div>            
    <% }%>
    <div><input type="hidden" value="<%= request.getAttribute("examCode")%>" name="examCode" id="examCode"/><input type="hidden" value="<%= str%>" name="orderQuestion" id="orderQuestion"/></div>
</div>
